package com.example.yeujian5.yuejian5.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.adapter.MasterVideoAdapter;
import com.example.yeujian5.yuejian5.bean.MasterVideoBean;
import com.example.yeujian5.yuejian5.model.Model;
import com.example.yeujian5.yuejian5.service.MasterService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * Created by wangmengmeng on 2017/10/24.
 */


public class VideoFragment extends Fragment {


    Intent intent;
    public  String Id;
    private RecyclerView recyclerView;
    private List<MasterVideoBean.MvideoEntity> list;
    private MasterVideoBean videoList;
    private View view;
    private Context context;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_video, container, false);
        init();
        event();
        return view;
    }
    public void init()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.video_Rec);
        context=getActivity();
    }
    public void event()
    {
        Intent intent=getActivity().getIntent();
        String Id=intent.getStringExtra("id");
        Retrofit retrofit= Model.getConn();
        MasterService masterService=retrofit.create(MasterService.class);
        Call<MasterVideoBean> call=masterService.getVideoList(Id,"mvideo");
        call.enqueue(new Callback<MasterVideoBean>() {
            @Override
            public void onResponse(Call<MasterVideoBean> call, Response<MasterVideoBean> response) {
                videoList=response.body();
                list=videoList.getMvideo();
                MasterVideoAdapter adapter=new MasterVideoAdapter(context,list);
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<MasterVideoBean> call, Throwable t) {

            }
        });
    }
}


